/**
 * 拖拽函数
 * @param target 点击触发拖拽事件的元素
 * @param moveEle 移动的元素
 */
export default (target, moveEle) => {
  target.onmousedown = function (e) {
    const disX = e.pageX - moveEle.offsetLeft;
    const disY = e.pageY - moveEle.offsetTop;

    document.onmousemove = function (e) {
      if (e.clientY <= 0 || e.clientY >= document.body.offsetHeight) {
        return
      }
      moveEle.style.margin = '0'
      moveEle.style.left = e.pageX - disX + 'px';
      moveEle.style.top = e.pageY - disY + 'px';
    }
    document.onmouseup = function () {
      document.onmousemove = null;
      document.onmouseup = null;
    }
  }
}
